<template>
	<view>
		<uni-forms border>
			<uni-forms-item label="收货人">
				<uni-easyinput :inputBorder="false" placeholder="请输入姓名" v-model="addressInfo.userName"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="手机">
				<uni-easyinput :inputBorder="false" placeholder="请输入手机号" type="number" v-model="addressInfo.userTel">
				</uni-easyinput>
			</uni-forms-item>
			<view class="area-box" >
				<view style="width: 80px;line-height: 57px;">
					<text>所在地区</text>
				</view>
				<pickerAddress @change='areaChange' style="width: 100%;line-height: 57px;margin-left: 10px;padding-left: 10rpx;">
					<view   style="display: flex; flex-direction: row;justify-content:space-between;width: 100%;flex-wrap: nowrap;">
						<text >{{addressInfo.area}}</text>
						<uni-icons type="arrowright" size="20"></uni-icons>
					</view>
				</pickerAddress>
			</view>
			<view class="area-box">
				<view style="width: 80px;padding-top: 20px;">
					<text>当前地址</text>
				</view>
				<textarea value="" placeholder="请输入详细地址" placeholder-style="font-size:14px" style="height: 200rpx;padding-top: 20px;box-sizing: border-box;padding-left: 10rpx;" v-model="addressInfo.address"/>
				<image src="../../static/tbw/position.svg" class="image-style" @click="getLocation"></image>
			</view>
			<uni-forms-item label="是否设为默认地址" >
				<switch  @change="switchChange"  />
			</uni-forms-item>
			
		</uni-forms>
		<view style="width: 200px;margin:20px auto;">
			<button type="primary" @click="addAdress()">完成添加</button>
		</view>
	</view>
</template>

<script>
	import pickerAddress from "../../components/wangding-pickerAddress/wangding-pickerAddress.vue"
	export default {
		components: {
			pickerAddress
		},
		data() {
			return {
				addressInfo: {
					userName: '',
					userTel: "",
					area: '当前地区',
					address: "",
					defaultAddress: ''
				}
			}
		},
		methods: {
			switchChange(e) {
				console.log(e.target.value)
				this.addressInfo.defaultAddress = e.target.value
			},
			areaChange(obj) {
				console.log(obj)
				this.addressInfo.area = obj.data.join("-")
			},
			getLocation(){
				
				uni.chooseLocation({
				    success: (res)=> {
						/* console.log(this)
				        console.log('位置名称：' + res.name);
				        console.log('详细地址：' + res.address);
				        console.log('纬度：' + res.latitude);
				        console.log('经度：' + res.longitude); */
						this.addressInfo.address=res.address
				    }
				});
			},
			addAdress(){
				// console.log(this.addressInfo)
				var pages=getCurrentPages()
				console.log(pages)
				var prevPage = pages[pages.length - 2]
				console.log(prevPage)
				prevPage.setData(
					{
						newAddressInfo:this.addressInfo
					}
				)
				uni.navigateBack({
				    delta: 1
				});
			}
		}
	}
</script>

<style scoped>
	.area-style {
		padding-left: 20rpx;
	}
	.line-container{
		display: flex;
		justify-content: space-between;
		padding-right: 20rpx;
		box-sizing: border-box;
		height: 100%;
	}
	.image-style{
		width: 80rpx;
		height: 80rpx;
		position: relative;
		right: 20rpx;
		top: 120rpx;
		
	}
	.area-box{
		display: flex;
		justify-content: flex-start;
		border-top: 1px #eee solid;
		font-size: 14px;
		/* align-items: baseline; */
	}
</style>
